package com.shanzmoo.admin.web.store;

import com.shanzmoo.admin.domain.dto.StorePurchaseSupplierSaveDTO;
import com.shanzmoo.admin.domain.dto.StorePurchaseSupplierUpdateDTO;
import com.shanzmoo.core.cache.CurrentUserCache;
import com.shanzmoo.db.store.entity.query.StorePurchaseSupplierQuery;
import com.shanzmoo.db.store.entity.vo.CheckSupplierVO;
import com.shanzmoo.db.store.entity.vo.StorePurchaseSupplierVO;
import com.shanzmoo.db.store.service.IStorePurchaseSupplierService;
import com.shanzmoo.db.store.entity.StorePurchaseSupplierEntity;
import com.shanzmoo.admin.manager.store.StorePurchaseSupplierManager;
import com.shanzmoo.base.bean.PageRespBase;
import com.shanzmoo.base.bean.SHttpResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;

import javax.validation.Valid;
import java.util.List;

/**
 * 仓库采购供应商 控制层
 *
 * @author xueqz 2021-03-03
 */
@Api(tags = "仓储-采购供应商")
@RestController
@RequestMapping("/store/purchase-supplier")
public class StorePurchaseSupplierController {

    @Autowired
    private IStorePurchaseSupplierService storePurchaseSupplierService;
    @Autowired
    private StorePurchaseSupplierManager storePurchaseSupplierManager;

    @ApiOperation(value = "分页列表")
    @PostMapping("/pageList")
    public SHttpResponse<PageRespBase<StorePurchaseSupplierVO>> pageList(@Valid @RequestBody StorePurchaseSupplierQuery query) {
        PageRespBase<StorePurchaseSupplierVO> pageList = storePurchaseSupplierManager.queryPage(query);
        return SHttpResponse.ok(pageList);
    }

    @ApiOperation(value = "添加")
    @PostMapping("/add")
    public SHttpResponse<Boolean> add(@Valid @RequestBody StorePurchaseSupplierSaveDTO saveDto) {
        saveDto.setCreateUser(CurrentUserCache.getUserId());
        storePurchaseSupplierService.save(saveDto.convertEntity());
        return SHttpResponse.ok(Boolean.TRUE);
    }

    @ApiOperation(value = "删除")
    @GetMapping("/delete")
    public SHttpResponse<Boolean> deleteById(@RequestParam(value = "id") Integer id) {
        storePurchaseSupplierService.deleteById(id);
        return SHttpResponse.ok(Boolean.TRUE);
    }

    @ApiOperation(value = "修改")
    @PostMapping("/update")
    public SHttpResponse<Boolean> update(@Valid @RequestBody StorePurchaseSupplierUpdateDTO updateDto) {
        updateDto.setUpdateUser(CurrentUserCache.getUserId());
        storePurchaseSupplierService.updateById(updateDto.convertEntity());
        return SHttpResponse.ok(Boolean.TRUE);
    }

    @ApiOperation(value = "选择列表")
    @PostMapping("/queryAllSupplier")
    public SHttpResponse<List<CheckSupplierVO>> queryAllSupplier(@Valid @RequestBody StorePurchaseSupplierQuery query) {
        List<CheckSupplierVO> pageList = storePurchaseSupplierManager.queryAllList(query);
        return SHttpResponse.ok(pageList);
    }
 }
